let app = getApp();
Page({
  data: {
    showAction: false,
    searchTxt: '',
    tabbar_active: 0,
    userInfo: {
      nickName: '',
    },
    resources: [],
    list: {
      pageNo: 1,
      pageSize: 5
    },
    categorys: []
  },
  onLoad() {
    this.loadCategory();
    this.loadResource();
  },

  loadCategory() {
    let option = {
      pageNo: 1,
      pageSize: 7
    }
    app.request('category/select/by/page', 'POST', option).then(res => {
      let categorys = res.data.list;
      categorys.push({
        categoryIcon: 'icon-tubiao-01',
        categoryName: '全部分类'
      })
      this.setData({
        categorys: categorys
      })
    });
  },
  loadResource() {
    let option = {
      pageNo: this.data.list.pageNo,
      pageSize: this.data.list.pageSize,
      is_list: ['eq', 1]
    };
    app.request('resource/select/by/page', 'POST', option).then(res => {
      this.setData({
        resources: res.data.list
      })
    })
  },
  handlerTabbar(e) {
    this.setData({
      tabbar_active: e.detail
    });
  },

  _navigate(e) {
    let url = e.currentTarget.dataset.url;
    console.log(url)
    wx.navigateTo({
      url: url,
    })
  },
  showAction() {
    this.setData({
      showAction: true
    });
  },
  hideAction() {
    this.setData({
      showAction: false,
      searchTxt: ''
    });
  },
  onSearch(e) {
    let url = '/subPackage/view/search/index';
    let t = e.currentTarget.dataset.t;
    let name = e.currentTarget.dataset.name;
    if (!name) {
      name = this.data.searchTxt;
    }
    if(name=='全部分类'){
      name="";
    }
    url += "?txt=" + name;
    if (t) {
      url += "&opt=" + t;
    }
    wx.navigateTo({
      url: url
    })
  }
})
